/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.gov.igac.observatorio.beans.idea;

import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;

/**
 *
 * @author bigbang
 */
@Named(value = "selectBean")
@SessionScoped
public class SelectBean implements Serializable {

    private static final String[] FRUITS = {"Banana", "Cranberry", "Blueberry", "Orange"};
    private static final String[] VEGETABLES = {"Potatoes", "Broccoli", "Garlic", "Carrot"};
    private String currentItem = null;
    private String currentType = null;
    private List<SelectItem> firstList = new ArrayList<SelectItem>();
    private List<SelectItem> secondList = new ArrayList<SelectItem>();

    public SelectBean() {
        SelectItem item = new SelectItem("fruits", "Fruits");
        firstList.add(item);
        item = new SelectItem("vegetables", "Vegetables");
        firstList.add(item);
        for (int i = 0; i < FRUITS.length; i++) {
            item = new SelectItem(FRUITS[i]);
        }
    }

    public void valueChanged(ValueChangeEvent event) {
        secondList.clear();
        if (null != event.getNewValue()) {
            String[] currentItems;
            if (((String) event.getNewValue()).equals("fruits")) {
                currentItems = FRUITS;
            } else {
                currentItems = VEGETABLES;
            }
            for (int i = 0; i < currentItems.length; i++) {
                SelectItem item = new SelectItem(currentItems[i]);
                secondList.add(item);
            }
        }
    }

    public String getCurrentItem() {
        return currentItem;
    }

    public void setCurrentItem(String currentItem) {
        this.currentItem = currentItem;
    }

    public String getCurrentType() {
        return currentType;
    }

    public void setCurrentType(String currentType) {
        this.currentType = currentType;
    }

    public List<SelectItem> getFirstList() {
        return firstList;
    }

    public void setFirstList(List<SelectItem> firstList) {
        this.firstList = firstList;
    }

    public List<SelectItem> getSecondList() {
        return secondList;
    }

    public void setSecondList(List<SelectItem> secondList) {
        this.secondList = secondList;
    }
}
//Getters and setters 
